﻿using System.Windows;
using System.Net;

namespace SlideShowDFG2
{
    /// <summary>
    /// Interaction logic for FtpConnectionWindow.xaml
    /// </summary>
    public partial class FtpConnectionWindow : Window
    {
        RegistryHelper _registry;

        public FtpConnectionWindow()
        {
            InitializeComponent();
        }
        
        public void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _registry = new RegistryHelper();
            base.DataContext = _registry;
            pbPassword.Password = _registry.FtpPassword;
        }

        private void btnOkay_Click(object sender, RoutedEventArgs e)
        {
            // We can try to connect now to see if the password and username are correct and the server is available
            WebClient client = WebClientHelper.GetNewInstance();

            try
            {
                client.DownloadString(_registry.FtpSaveDir
            }

            _registry.FtpPassword = pbPassword.Password;
            base.DialogResult = true;
            base.Close();
        }

#pragma warning disable 0162
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to save changes?", "Save Changes?",
                                                        MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
            switch (result)
            {
                case MessageBoxResult.Cancel :
                    return; break;
                case MessageBoxResult.Yes :
                    _registry.FtpPassword = pbPassword.Password;
                    base.DialogResult = true;
                    base.Close();
                    break;
                case MessageBoxResult.No :
                    base.DialogResult = false;
                    base.Close();
                    break;
            }
        }
    }
}
